#!/usr/bin/env python  第一行注释是为了告诉Linux/OS X系统，这是一个Python可执行程序，Windows系统会忽略这个注释；
# -*- coding: utf-8 -*-  第二行注释是为了告诉Python解释器，按照UTF-8编码读取源代码，否则，你在源代码中写的中文输出可能会有乱码。


import random


def methods():
    a = ['python', 'java', 'c++', 1, 2, 3, 4, 5, 6]
    lst = [1, 2, 3, 4, 5, 6]
    print len(a)
    lst = lst + a
    print lst
    if 'python' in lst:
        print 'true'
    print max(lst)
    print min(lst)


# 重要特征：列表是可以修改的。这种修改，不是复制一个新的，而是在原地进行修改。
def methods2():
    a = ['python', 'java', 'c++', 1, 2, 3, 4, 5, 6]
    lst = [1, 2, 3, 4, 5, 6]
    lst.extend(a)
    print lst


def methods3():
    astr = "hello world"
    if hasattr(astr, '__iter__'):  # 判定是否具有迭代iterator能力
        print True
    else:
        print False


def methods4():
    lst = [1, 2, 3]
    lst.append(["qiwsir", "github"])  # append是整建制地追加，extend是个体化扩编。
    print len(lst)
    lst2 = [1, 2, 3]
    lst2.extend(["qiwsir", "github"])
    print len(lst2)


def methods5():
    lst = [1, 2, 3]
    lst.insert(0, 1)
    print lst


def methods6():
    line = "Hello.I am qiwsir.Welcome you."
    print line.split(".")
    print line.split(".", 1)
    print line.split()
    line2 = ['I', 'am,', 'writing', 'python', 'book', 'on', 'line']
    print " ".join(line2)
    print " ".join(line2).replace(',', '')


def testfor():
    line2 = ['I', 'am,', 'writing', 'python', 'book', 'on', 'line']
    for w in line2:
        print w


def randomsample():
    line2 = ['I', 'am,', 'writing', 'python', 'book', 'on', 'line']
    print random.sample(line2, 1)  # 随机获取满足条件中的一个值，灰常有用的一个函数


if __name__ == '__main__':
    print "==============================="
    methods()
    print "==============================="
    methods2()
    print "==============================="
    methods3()
    print "==============================="
    methods4()
    print "==============================="
    methods5()
    print "==============================="
    methods6()
    print "-" * 50
    testfor()
    print "-" * 50
    randomsample()
